﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TCM.Controllers
{
    public class SubjectLevelController : Controller
    {
        private TCMContext db = new TCMContext();

        //
        // GET: /SubjectLevel/

        public ActionResult Index()
        {
            var LEVELBASEs = db.LEVELBASEs.Include(s => s.MAPSTRINGBASE).Include(s => s.SUBJECTBASE);
            return View(LEVELBASEs.ToList());
        }

        //
        // GET: /SubjectLevel/Details/5

        public ActionResult Details(Guid ? id = null)
        {
            LEVELBASE LEVELBASE = db.LEVELBASEs.Find(id);
            if (LEVELBASE == null)
            {
                return HttpNotFound();
            }
            return View(LEVELBASE);
        }

        //
        // GET: /SubjectLevel/Create

        public ActionResult Create()
        {
            
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYNAME");
            ViewBag.SUBJECTID = new SelectList(db.SUBJECTBASEs, "SUBJECTID", "NAME");
            return View();
        }

        //
        // POST: /SubjectLevel/Create

        [HttpPost]
        public ActionResult Create(LEVELBASE LEVELBASE)
        {
            if (ModelState.IsValid)
            {
                LEVELBASE.LEVELID = Guid.NewGuid();
                db.LEVELBASEs.Add(LEVELBASE);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYNAME", LEVELBASE.STATUSID);
            ViewBag.SUBJECTID = new SelectList(db.SUBJECTBASEs, "SUBJECTID", "NAME", LEVELBASE.SUBJECTID);
            return View(LEVELBASE);
        }

        //
        // GET: /SubjectLevel/Edit/5

        public ActionResult Edit(Guid ?id = null)
        {
            LEVELBASE LEVELBASE = db.LEVELBASEs.Find(id);
            if (LEVELBASE == null)
            {
                return HttpNotFound();
            }
            
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYNAME", LEVELBASE.STATUSID);
            ViewBag.SUBJECTID = new SelectList(db.SUBJECTBASEs, "SUBJECTID", "NAME", LEVELBASE.SUBJECTID);
            return View(LEVELBASE);
        }

        //
        // POST: /SubjectLevel/Edit/5

        [HttpPost]
        public ActionResult Edit(LEVELBASE LEVELBASE)
        {
            if (ModelState.IsValid)
            {
                db.Entry(LEVELBASE).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYNAME", LEVELBASE.STATUSID);
            ViewBag.SUBJECTID = new SelectList(db.SUBJECTBASEs, "SUBJECTID", "NAME", LEVELBASE.SUBJECTID);
            return View(LEVELBASE);
        }

        //
        // GET: /SubjectLevel/Delete/5

        public ActionResult Delete(Guid? id = null)
        {
            LEVELBASE LEVELBASE = db.LEVELBASEs.Find(id);
            if (LEVELBASE == null)
            {
                return HttpNotFound();
            }
            return View(LEVELBASE);
        }

        //
        // POST: /SubjectLevel/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(Guid id)
        {
            LEVELBASE LEVELBASE = db.LEVELBASEs.Find(id);
            db.LEVELBASEs.Remove(LEVELBASE);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}